﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Account
/// </summary>
public class Account
{
    private string id = null;
    private string balance = null;
    private string creation_date = null;
    private string incomes_count = null;
    private string outcomes_count = null;
    private Dictionary<Configuration.AccountAttributes, string> dic;

    public string Id { get { return this.id; } set { this.id = value;  } }
    public string Balance { get { return this.balance; } set { this.balance = value; } }
    public string CreationDate { get { return this.creation_date; } set { this.creation_date = value; } }
    public string IncomesCount { get { return this.incomes_count; } set { this.incomes_count = value; } }
    public string OutcomesCount { get { return this.outcomes_count; } set { this.outcomes_count = value; } }


    public Account() 
    {
        this.id = "";
        this.balance = "0";
        this.creation_date = DateTime.Now.ToShortDateString();
        this.incomes_count = "0";
        this.outcomes_count = "0";
    }

    public Account(string id, string balance, string creation_date,
                   string incomes_count, string outcomes_count
                  )
    {
        this.id = id;
        this.balance = balance;
        this.creation_date = creation_date;
        this.incomes_count = incomes_count;
        this.outcomes_count = outcomes_count;
    }

    public Account(Dictionary<Configuration.AccountAttributes, string> values)
    {
        foreach (Configuration.AccountAttributes att in values.Keys)
            switch (att)
            {
                /*case Configuration.AccountAttributes.id: this.id = values[att];
                                                  break;*/
                case Configuration.AccountAttributes.balance: this.balance = values[att];
                                                       break;
                case Configuration.AccountAttributes.creation_date: this.creation_date = values[att];
                                                             break;
                case Configuration.AccountAttributes.incomes_count: this.incomes_count = values[att];
                                                             break;
                case Configuration.AccountAttributes.outcomes_count: this.outcomes_count = values[att];
                                                               break;
            }
    }

    public static Account newInstance(string[] values)
    {
        if (values.Length != Configuration.AccountAttributesCount)
            return null;

        return new Account(values[0], values[1], values[2], values[3], values[4]);
    }


    public Dictionary<Configuration.AccountAttributes, string> toDictionary()
    {
        dic = new Dictionary<Configuration.AccountAttributes, string>();
        dic.Add(Configuration.AccountAttributes.id, this.id);
        dic.Add(Configuration.AccountAttributes.balance, this.balance);
        dic.Add(Configuration.AccountAttributes.creation_date, this.creation_date);
        dic.Add(Configuration.AccountAttributes.incomes_count, this.incomes_count);
        dic.Add(Configuration.AccountAttributes.outcomes_count, this.outcomes_count);
        return dic;
    }

    public string[] toArray()
    {
        return this.toDictionary().Values.ToArray<string>();
    }

}
